package com.rice.study.Controller;

import com.alibaba.fastjson.JSONObject;
import com.rice.study.Service.TestService;
import com.rice.study.common.ResponseDto;
import com.rice.study.common.ReturnCode;
import com.rice.study.dao.Tester;
import com.sun.corba.se.impl.ior.OldJIDLObjectKeyTemplate;
import io.swagger.models.auth.In;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.swing.text.html.Option;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;


@RestController
public class TController{
    Logger log = LoggerFactory.getLogger(TController.class);

    @Autowired
    TestService testService;

    @GetMapping(value = "/test")
    public ResponseDto<Tester> getTest(@RequestParam("id") Integer id){
        log.info(id+"");
//        for (int i = 0; i < 2; i++) {
//            String name = UUID.randomUUID().toString().replaceAll("-","");
//            Tester t = new Tester(name);
//            testService.save(t);
//        }
        Tester tester = testService.getTestDb(id);
        Tester tester2 = testService.getById(id);
        return ResponseDto.isSuccessResponse(tester2);
    }


    @GetMapping(value = "/save")
    public ResponseDto<List<Integer>> save(){
        List<Integer> ids = new ArrayList<>();
        for (int i = 0; i < 2; i++) {
            String name = UUID.randomUUID().toString().replaceAll("-","");
            Tester t = new Tester(name);
            Integer idDB = testService.save(t);
            String str = JSONObject.toJSONString(testService.getById(idDB));
            log.info(str);
            ids.add(idDB);
        }
//        for (int i = 0; i < 5; i++) {
//            String str = JSONObject.toJSONString(testService.getById(82));
//            log.info(str);
//        }
        return ResponseDto.isSuccessResponse(ids);
    }


}
